﻿namespace WMS6.Web
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Web;
    using WMS6.Web.OutboundDetailServiceRef;

    public class OutboundDetailServiceClientProxy : BasePage
    {
        public string DeleteWave(string waveID, List<string> IDS)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                result = client.DeleteWave(waveID, IDS, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public DataSet GetAllWaveDetailInfo()
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                ds = client.GetAllWaveDetailInfo(pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        public static OutboundDetailServiceClientProxy GetInstance()
        {
            return new OutboundDetailServiceClientProxy();
        }

        public IntransitDetailInfo GetIntransitDetailInfoByID(string IntransitID, string LineID, string srcDbID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            IntransitDetailInfo intransitDetailInfo = null;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                intransitDetailInfo = client.GetIntransitDetailInfoByID(IntransitID, LineID, srcDbID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return intransitDetailInfo;
        }

        public DataSet GetOrderDetailInfoByPagerQueryEntity(OrderDetailQueryEntity orderDetailQueryEntity)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            DataSet ds = null;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                ds = client.GetOrderDetailInfoByPagerQueryEntity(orderDetailQueryEntity, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return ds;
        }

        private PubParasInfo InitPubParasInfo()
        {
            if (base.UserInfo != null)
            {
                return new PubParasInfo { UserID = base.UserInfo.UserID, UserLanguage = base.UserInfo.Preference.Lang, CurrentWH = base.UserInfo.CurrentWH };
            }
            HttpContext.Current.Response.Redirect("../Login.aspx?from=Logout", true);
            return null;
        }

        public string InserOrderDetailByReceipt(string orderid, List<string> receiptID, List<string> receiptLineID)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                result = client.InserOrderDetailByReceipt(orderid, receiptID, receiptLineID, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string InsertWaveDetail(WaveDetailInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                result = client.InsertWaveDetail(obj, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string SaveWavebyOrderSelection(WaveDetailInfo waveDetailInfo, List<string> IDS, List<string> Status)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                result = client.SaveWavebyOrderSelection(waveDetailInfo, IDS, Status, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }

        public string UpdateWaveDetail(WaveDetailInfo obj)
        {
            PubParasInfo pubParasInfo = this.InitPubParasInfo();
            string result = string.Empty;
            OutboundDetailServiceClient client = new OutboundDetailServiceClient("WSHttpBinding_IOutboundDetailService");
            try
            {
                result = client.UpdateWaveDetail(obj, pubParasInfo);
                client.Close();
            }
            catch (Exception ex)
            {
                client.Abort();
                SysLog.GetInstance().LogProxyError(ex);
            }
            return result;
        }
    }
}

